<?php

/**
 * Application form.
 *
 * @package    wills
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ApplicationForm extends BaseApplicationForm
{
  public function configure()
  {
    unset(
      $this['created_at'], 
      $this['updated_at']
    );

	$this->setWidget('password', new sfWidgetFormInputPassword())
      ->setWidget('password2', new sfWidgetFormInputPassword());
	//添加默认请选择赛区
	$this->setWidget('area_id', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('area'), 'add_empty' => '请选择赛区')));

	$this->validatorSchema['email'] = new sfValidatorAnd(array(
		$this->validatorSchema['email'],
		new sfValidatorEmail(),
	   ));
    $this->validatorSchema['email']->setMessages(array(
      'required' => 'Email不能为空',
      'invalid'  => 'Email格式不正确'
    ))->setOption('trim', true);

    $this->validatorSchema['password'] = new sfValidatorString(
      array('min_length' => '6'), 
      array('min_length' => '密码长度不够')
    );

    $this->validatorSchema['password']->setMessages(array('required' => '密码不能为空'));
    $this->validatorSchema['password2'] = new sfValidatorString();

  //email、身份证号唯一，密码两次相等判断
    $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
      new sfValidatorDoctrineUnique(
        array('model' => 'Application', 'column' => array('email')), 
        array('invalid' => '此Email已经存在')
      ),

      new sfValidatorDoctrineUnique(
        array('model' => 'Application', 'column' => array('id_card')), 
        array('invalid' => '此身份证号已经存在')
      ),
      
      new sfValidatorSchemaCompare(
        'password',
        sfValidatorSchemaCompare::EQUAL,
        'password2',
        array(), array('invalid' => '两次输入的密码不一致')
      )
    )));

  //个人介绍、才艺和爱好、美丽宣言。添加默认值
    $this->widgetSchema['introduction'] = new sfWidgetFormTextArea(array('default' => '请填写参加过的选美活动或参加过的广告拍摄，限200字以内。'));
    $this->widgetSchema['hobby'] = new sfWidgetFormTextArea(array('default' => '限100字以内。'));
    $this->widgetSchema['watchword'] = new sfWidgetFormTextArea(array('default' => '将作为您的个人说明出现在佳丽推荐页面，限50字以内。'));
   
	//设置验证提示。网站为非必填项，本程序不用填写英文名字;
    $this->validatorSchema['name']->setMessage('required', '名字不能为空');
	$this->validatorSchema['address']->setMessage('required', '请填写现居住地址');
	$this->validatorSchema['age']->setMessage('required', '请填写年龄');
	$this->validatorSchema['minzu']->setMessage('required', '请填写民族');
	$this->validatorSchema['height']->setMessage('required', '请填写身高');
	$this->validatorSchema['weight']->setMessage('required', '请填写体重');
	$this->validatorSchema['bwh']->setMessage('required', '请填写三围');
	$this->validatorSchema['occupation']->setMessage('required', '请填写职业');
	$this->validatorSchema['education']->setMessage('required', '请填写学历');
	$this->validatorSchema['college']->setMessage('required', '请填写毕业就读院校');
	
	$this->validatorSchema['id_card']->setMessage('required', '请填写您的身份证号码');
	$this->validatorSchema['phone']->setMessage('required', '请填写您的联系电话');
	$this->validatorSchema['native_place']->setMessage('required', '请填写您的联系地址');
	$this->validatorSchema['qq']->setMessage('required', '请填写QQ');
	$this->validatorSchema['contact']->setMessage('required', '请填写紧急联系人');
	$this->validatorSchema['relation']->setMessage('required', '请填写紧急联系人和您的关系');
	$this->validatorSchema['contact_phone']->setMessage('required', '请填写紧急联系人电话');
	$this->validatorSchema['introduction']->setMessage('required', '请填写个人介绍');
	$this->validatorSchema['watchword']->setMessage('required', '请填写美丽宣言');
	$this->validatorSchema['hobby']->setMessage('required', '请填写才艺和爱好');

    $this->validatorSchema['name_en']->setOption('required', false);//本程序无
    $this->validatorSchema['area_id']->setOption('required', false);
    //$this->validatorSchema['password']->setOption('required', false);
    //$this->validatorSchema['password2']->setOption('required', false);
	
//艺术照
	$this->widgetSchema['picture'] = new sfWidgetFormInputFile();
    $this->validatorSchema['picture'] = new sfValidatorFile(array(
      'max_size' => 3 * 1024 * 1024,
      'path' => Wills::getUploadDirByWebPath(sfConfig::get('app_path_application_picture')),
      'mime_types' => 'web_images'
    ));
    $this->validatorSchema['picture']->setOption('required', true);
    $this->validatorSchema['picture']->setMessage('required', '请上传艺术照片');
//生活照	
	$this->widgetSchema['picturelife'] = new sfWidgetFormInputFile();
	$this->validatorSchema['picturelife'] = new sfValidatorFile(array(
      'max_size' => 3 * 1024 * 1024,
      'path' => Wills::getUploadDirByWebPath(sfConfig::get('app_path_application_picturelife')),
      'mime_types' => 'web_images'
    ));
    $this->validatorSchema['picturelife']->setOption('required', true);
    $this->validatorSchema['picturelife']->setMessage('required', '请上传生活照片');

  }
}
